package com.alinu.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author chenzuwei
 * @date 2021/3/15
 * @description
 */
public final class StringUtil {
    private StringUtil() {
    }

    /**
     * 判断字符串非空、非空字符
     *
     * @param param 参数
     * @return t/f
     */
    public static boolean isNotEmpty(String param) {
        return param != null && !"".equals(param.trim());
    }

    /**
     * 判断字符串空、空字符
     *
     * @param param 参数
     * @return t/f
     */
    public static boolean isEmpty(String param) {
        return param == null || "".equals(param.trim());
    }

    /**
     * 检验字符串是否为数字
     *
     * @param number 字符串数字
     * @return t/f
     */
    public static boolean isNumber(String number) {
        String regex = "^(-?\\d+)(\\.\\d+)?$";
        return matchRegex(number, regex);
    }

    /**
     * 匹配检验
     *
     * @param number 字符串数字
     * @param regex  检验正则
     * @return t/f
     */
    private static boolean matchRegex(String number, String regex) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(number);
        return matcher.matches();
    }


}
